class FontSetting 

  # Attributes
  attr_reader :mfc_class_name
  attr_reader :mfc_class_schema

  attr_reader :face_name
  attr_reader :point_size
  attr_reader :weight
  attr_accessor :color

  # Constants
  DEFAULT_FACENAME = "Times New Roman"
  DEFAULT_POINTSIZE = 8
  DEFAULT_WEIGHT = WEIGHT_NORMAL
  DEFAULT_ITALIC = 0
  DEFAULT_UNDERLINE = 0
  DEFAULT_STRIKEOUT = 0
  DEFAULT_COLOR = [ 0, 0, 0 ]
   
  MIN_POINTSIZE = 1
  MAX_POINTSIZE = 72
   
  WEIGHT_DONT_CARE = 0
  WEIGHT_THIN = 100
  WEIGHT_EXTRA_LIGHT = 200
  WEIGHT_ULTRA_LIGHT = 200
  WEIGHT_LIGHT = 300
  WEIGHT_NORMAL = 400
  WEIGHT_REGULAR = 400
  WEIGHT_MEDIUM = 500
  WEIGHT_SEMI_BOLD = 600
  WEIGHT_DEMI_BOLD = 600
  WEIGHT_BOLD = 700
  WEIGHT_EXTRA_BOLD = 800
  WEIGHT_ULTRA_BOLD = 800
  WEIGHT_BLACK = 900
  WEIGHT_HEAVY = 900
   
  # Constructor
  def initialize(face_name = DEFAULT_FACENAME, point_size = DEFAULT_POINTSIZE, weight = DEFAULT_WEIGHT, italic = DEFAULT_ITALIC, underline = DEFAULT_UNDERLINE, strike_out = DEFAULT_STRIKEOUT, color=DEFAULT_COLOR) 

    mfc_class_name = "CFontItem"
    mfc_class_schema = 1

    return false unless face_name
    return false unless valid_point_size?(point_size)
    return false unless valid_weight?(weight)
    
    color = DEFAULT_COLOR unless color
    
    font_setting=(face_name, point_size, weight, italic, underline, strike_out, color) 

  end
   
  # Methods
  def face_name=(face_name) 
    return false unless face_name
    @face_name = face_name
    return true
  end
   
  def valid_point_size?(point_size) 
    return ((point_size >= MIN_POINTSIZE) && (point_size <= MAX_POINTSIZE))
  end
   
  def point_size=(point_size) 
    return false unless valid_point_size?(point_size)
    @point_size = point_size
    return true
  end
   
  def valid_weight?(weight) 
    return (((weight >= WEIGHT_DONT_CARE) && (weight <= WEIGHT_HEAVY)) && ((weight % 100) == 0))
  end
   
  def weight=(weight) 
    return false unless valid_weight?(weight)
    @weight = weight
    return true
  end

  def italic!(set = true) 
    @italic = set
  end
   
  def italic?
    return (@italic == true)
  end
   
  def underline!(set = true) 
    @underline = set
  end
   
  def underline?
    return (@underline == true)
  end
   
  def strike_out!(set = true) 
    @strike_out = set
  end
   
  def strike_out?
    return (@strike_out == true)
  end
   
  def font_setting=(face_name, point_size, weight, italic, underline, strike_out, color) 
    return false unless face_name=(face_name)
    return false unless point_size=(point_size)
    return false unless weight=(weight)
    italic!(italic)
    underline!(underline)
    strike_out!(strike_out)
    @color = color
    return true
  end
   
  # Serialization  
  def do_serialize(stream)   
    write_cstring(stream, @face_name)
    write_signed_integer(stream, @point_size)
    write_signed_integer(stream, @weight)
    write_byte(stream, @italic)
    write_byte(stream, @underline)
    write_byte(stream, @strike_out)
    write_color_ref(stream, @color)
    return true
  end
   
  def do_deserialize(stream)
    @face_name = read_cstring(stream)
    @point_size = read_signed_integer(stream)
    @weight = read_signed_integer(stream)
    @italic = read_byte(stream)
    @underline = read_byte(stream)
    @strike_out = read_byte(stream)
    read_color_ref(stream, @color)
  end
   
end
